<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>发表评论</title>
    <base href="<%=basePath%>"/>
    <%@ include file="../../cuv_include.jsp"%>
    <style type="text/css">
  		fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
  		form label {font-weight:bold;}
    	table{margin:10px 10px};
  		td{line-height: 40px;}
		input[type="text"]{width:250px;}
		input[type="password"]{width:250px;}
		input[type="textarea"]{width:250px;}   		
    </style>
	<script type="text/javascript">
	
	 $(document).ready(function(){
		     var options = {dataType: 'json',beforeSubmit: beforeSubmit, success: process};
		     $("#formComment").submit(function(){
		         $(this).ajaxSubmit(options);
		         return false;
		     });      
		  });
	
		  //提交前验证
		  function beforeSubmit() {
			     if(isEmpty($("#content").val())) { alert("评论不能为空！"); return false; }
			     return ;
		  }
		  function process(responseJson) {
		      if(responseJson.code == 0) {
		          $('#error_label').text("错误信息：" + responseJson.message);
		          $("#p_error").show();
		          return;
		      }
		      location.reload();
	  }
	  //返回列表页面
     function btn_return(){
    	  var qs = $("#qs").val();
 	     location.href = "<%=basePath%>soft/bug/list.do?" + qs;
	 }
	</script>
</head>
<body>
      <div id="div2">
      	<p id = "p_error" style = "margin:10px 10px;">
      	<label id="error_label" style="color:red;"></label>
      	</p>
		<fieldset id="bugTrail">
			<legend>Bug评论：</legend>
			  <input id="qs" name="qs" type="hidden" value="${qs}"/>
			  <c:if test="${commentList == null || fn:length(commentList) == 0}">
				<p>
					<c:out value="暂时无评论"></c:out>
				</p>
			 </c:if>
			<c:forEach items="${commentList}" var="comment">
				<table style="border-bottom:1px dotted;">
					<tr>
						<td width="15%"><label>评论人：</label></td>
						<td width="35%"><label>${comment.userCnname}</label></td>
						<td width="15%"><label>时间：</label></td>
						<td width="35%">
						<label> <fmt:formatDate value="${comment.createTime}" type="both" dateStyle="medium" timeStyle="medium" />
						</label>
						</td>
					</tr>
					<tr>
						<td><label for="content">描述：</label></td>
						<td colspan="3">${comment.content}
						</td>
					</tr>
				</table>
			</c:forEach>
            <hr>
			<c:if test="${currentStatus =='close'}">
			   <input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
            </c:if>
			<div  <c:if test="${currentStatus =='close'}">style="display:none"</c:if>>
			<form id="formComment" name="formComment" action="soft/bug/commentinsert.do" method="post" >
				<table>
					<tr>
						<td align="left"><label>评论人： </label></td>
						<td align="left">
						    <label>${sessionScope.usercnname}</label>
						    <input type="hidden"  id="objectId" name="objectId" value="${bug.id}"/>
						    <input type="hidden"  id="userEnname" name="userEnname" value="${sessionScope.username}"/>
							<input type="hidden"  id="objectType" name="objectType" value="4"/>
						
						</td>
					</tr>
					<c:if test="${sessionScope.username != bug.expurgator }">
						<tr>
							<td align="left"><label for="expurgator">修订人： </label></td>
							<td align="left">
								<select name="expurgator" id="expurgator" style="width:154px">
								  <c:forEach items="${userList}" var="user">
								     <option value="${user.enname}"  <c:if test="${user.enname == bug.expurgator}">selected="selected"</c:if>>${user.cnname} </option>
								  </c:forEach>
	                       		</select>
							</td>
						</tr>
					</c:if>
					<c:if test="${sessionScope.username == bug.expurgator }">
						<input type="hidden"  name="expurgator" id="expurgator" value="${bug.expurgator}"/>
					</c:if>
					<tr>
						<td><label>当前状态：</label></td>
						<td align="left">
						    <select disabled="disabled" style="width:154px">
							   <c:forEach items="${itemList}" var="s">
							      <option <c:if test="${s.value == currentStatus}"> selected="selected"</c:if>>${s.name}</option> 
							   </c:forEach>
							</select>
						</td>
					</tr>
					<tr>
						<td><label for="status">接下状态：</label></td>
						<td>
						     <select name="status" id="status" style="width:154px" >
						         <c:forEach items="${types}" var="type">
							          <c:if test="${type == '0' }">  <!-- 开发人员 -->
									         <option value="fix"> 修复</option>
							          </c:if>
							          <c:if test="${type == '2' }">  <!-- 测试人员 -->
							                 <c:if test="${ currentStatus == 'new' }">  
									            <option value="new">新建</option>
							                 </c:if>
									         <option value="close">关闭</option>
									         <option value="reopen">重启</option>
							          </c:if>
							          <c:if test="${type == '3' }">  <!-- 项目经理 -->
									         <option value="open">打开</option>
									         <option value="fix" <c:if test="${ currentStatus == 'fix'}">selected="selected"</c:if>> 修复</option>
									         <option value="reject">拒绝</option>
							          </c:if>
						          </c:forEach>
							 </select>
						</td>
					</tr>
					<tr>
						<td valign="top"><label for="comment">评论意见：</label></td>
						<td><textarea name="content" id="content" cols="30" rows="6"></textarea><font color="red">&nbsp;*&nbsp;&nbsp;</font></td>
					</tr>
					<tr>
						<td></td>
						<td>
						   <input type="submit" id="btn_insert" value="提交" style="width:80px;" />
						   <input type="button" id="btn_back" value="返回" onclick="btn_return();" style="width: 80px;" />
						</td>
					</tr>
				</table>
			</form>
			</div>
		</fieldset>
	</div>
</body>
</html>